// K&R book. C7, p12.
// cat function.

#include <stdio.h>

int main(int argc, char **argv)
{
    FILE *fp;
    void filecopy(FILE *, FILE *);

    if (argc == 1)
        filecopy(stdin, stdout);
    else
        while (--argc > 0)
        {
            if ((fp = fopen(*++argv, "r")) == NULL)
                printf("Cat: can't open file: %s\n", *argv);
            else
            {
                filecopy(fp, stdout);
                fclose(fp);
            }
        }
    return 0;
}

void filecopy(FILE *infile, FILE *outfile)
{
    char c;

    while ((c = getc(infile)) != EOF)
        putc(c, outfile);
}